/**
 * @author yaoyuan
 * @version 1.0
 * @name zjzcVotingApp.controller:voteEditCtrl
 * @description 用户登录
 */

'use strict';

angular.module('zjzcVotingApp')
  .controller('voteEditCtrl', ['$scope', '$stateParams', '$uibModal', 'FileUploader', function ($scope, $stateParams, $uibModal, FileUploader) {
    var P = {}, vm;

    $scope.installCtrl = function() {
        $scope.vm = {datas:{}},
        vm = $scope.vm;
        P.getDetail($stateParams.id);
    }

    $scope.$on('editor:load', function(event, editor) {
        $scope.editor = editor;

    });
    /**
     * [banner 活动Banner方法集合]
     */
    $scope.banner = {
        data : [],
        install: function() {
            return {
                picPath:'',
                order: 1,
                link: '',
                description:''
            }
        },
        edit: function(item) {
            var that = this;
            var modalInstance = $uibModal.open({
                templateUrl: 'bannerTemp.html',
                controller: ['$scope', '$uibModalInstance', 'bitem', function($scope, $uibModalInstance, bitem) {
                    $scope.vm = {item: bitem};
                    var vm = $scope.vm;
                    $scope.ok = function() {
                        vm.item.order = vm.item.order*1;
                        $uibModalInstance.close(vm.item);
                    }

                    $scope.cancel = function() {
                        $uibModalInstance.dismiss('cancel');
                    }
                }],
                resolve: {
                bitem: function () {
                    return item || {
                            sn: 0,
                            picPath:'',
                            order: 1,
                            link: '',
                            description:''
                        };
                    }
                }
            });

            modalInstance.result.then(function (item) {
                that.data.push(item);
            });
        },
        del: function() {

        }
    };

    $scope.element = {
        data: [],
        install: function() {},
        edit: function(item) {
            var that = this;
            var modalInstance = $uibModal.open({
                templateUrl: 'elementTemp.html',
                controller: ['$scope', '$uibModalInstance', 'eitem', function($scope, $uibModalInstance, eitem) {
                    $scope.vm = {item: eitem};
                    var vm = $scope.vm;
                    $scope.ok = function() {
                        vm.item.order = vm.item.order*1;
                        $uibModalInstance.close(vm.item);
                    }

                    $scope.cancel = function() {
                        $uibModalInstance.dismiss('cancel');
                    }
                }],
                resolve: {
                eitem: function () {
                    return item || {
                            sn: 0,
                            picPath:'',
                            order: 1,
                            link: '',
                            description:''
                        };
                    }
                }
            });

            modalInstance.result.then(function (item) {
                that.data.push(item);
            });
        }
    };
    P.getDetail = function(sn){
        if(!sn) return;

    }

    $scope.save = function() {

    }
  }]);
